<%- include('header') %>

<form class="ui form segment" method="post" enctype="multipart/form-data" action="/posts"
      style="margin-left: 20px; margin-right: 20px">
    <% if ('教师' != user.identity && '管理员' != user.identity) { %>
    <div id="student_id_div" class="field">
        <label>学生学号</label>
        <input value="<%- user.student_id %>" type="text" name="student_id" readonly>
    </div>
    <% } %>
    <% if ('教师' == user.identity || '管理员' == user.identity) { %>
    <div id="student_select_div" class="field required">
        <label>选择学生</label>
        <select id="student_select" class="ui compact selection dropdown" name="student_id">
            <% for ( var i = 0; i < students.length; i++ ) {
                var selected = ( 0 == i ) ? "selected" : "";
            %>
            <option value="<%=students[i].student_id %>" <%=selected %>><%=students[i].student_id %> <%=students[i].student_name %></option>
            <% } %>
        </select>
    </div>
    <% } %>
    <div class="field required">
        <label>标题</label>
        <input type="text" name="title">
    </div>
    <div class="field required">
        <label>内容</label>
        <textarea name="content" rows="5"></textarea>
    </div>
    <div id="select_photo_div" class="field">
        <a id="select_photo" href="javascript:;" class="a-upload">
            <input type="file" name="photos" id="select_photo_input" accept="image/*" multiple="multiple"
                   onchange="onPhotoSelected()">选择照片
        </a>
        <label id="selected_photo"></label>
    </div>
    <div id="capture_photo_div" class="field" style="display: none">
        <a id="capture_photo" href="javascript:;" class="a-upload">
            <input type="file" name="photos" id="capture_photo_input" accept="image/*" capture="camera"
                   onchange="onCapture()">拍摄照片
        </a>
        <label id="captured_photo"></label>
    </div>
    <input type="submit" class="ui button" value="提交">
</form>

<script>
    function hide(view_id) {
        var ui =document.getElementById(view_id);
        ui.style.display="none";
    }

    function  onCapture(obj) {
        hide('select_photo_div');
        var f = document.getElementById("capture_photo_input").files;
        document.getElementById("captured_photo").innerHTML=f[0].name;
    }

    function onPhotoSelected(obj) {
        hide('capture_photo_div');
        var f = document.getElementById("select_photo_input").files;
        document.getElementById("selected_photo").innerHTML=f[0].name;
    }

    document.getElementById("description").innerHTML="图文上传";

    var browser = {
        versions: function () {
            var u = navigator.userAgent, app = navigator.appVersion;
            return {         //移动终端浏览器版本信息
                trident: u.indexOf('Trident') > -1, //IE内核
                presto: u.indexOf('Presto') > -1, //opera内核
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
                iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf('iPad') > -1, //是否iPad
                webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
            };
        }(),
        language: (navigator.browserLanguage || navigator.language).toLowerCase()
    }

    if (browser.versions.android) {
        document.getElementById("capture_photo_div").style.display = "";
    }
</script>

<%- include('footer') %>